package com.hangzhou.xyj.ui.adapter;


import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.model.DramaCategoryModel;
import com.hangzhou.xyj.ui.widget.views.MyTextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by neo.duan on 2015/12/22.
 * 剧种adapter
 */
public class DramaAdapter extends BaseAdapter{
    private static final int ITEM_COUNT = 10;
    private Context mContext;
    private List<DramaCategoryModel> mData;

    public DramaAdapter(Context context, List<DramaCategoryModel> data) {
        this.mContext = context;
        if (data == null || data.isEmpty()) {
            mData = new ArrayList<>();
        }
        this.mData = data;
    }

    @Override
    public int getCount() {
        if (mData == null) {
            return 0;
        }
        if (mData.size() >= ITEM_COUNT - 1) {
            return ITEM_COUNT;
        }
        return mData.size();
    }

    @Override
    public DramaCategoryModel getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = View.inflate(mContext, R.layout.layout_drama_item, null);
        //最后一个:更多
        if (getCount() == ITEM_COUNT && position == (getCount() - 1)) {
        	MyTextView textView = (MyTextView)view.findViewById(R.id.tv_drama_item);
        	textView.setText("更多");
        } else {
        	MyTextView textView = (MyTextView)view.findViewById(R.id.tv_drama_item);
        	textView.setText(getItem(position).getName());
            if (getItem(position).isSelected()) {
                textView.setTextColor(mContext.getResources().getColor(R.color.common_white));
            } else {
                textView.setTextColor(mContext.getResources().getColor(R.color.common_purple));
            }
        }
        return view;
    }
}
